package com.zk.controller;

import com.zk.po.Dynamic;
import com.zk.service.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kun
 * @since 2022-06-08
 */
@CrossOrigin(origins = "*",allowedHeaders = "*", maxAge = 3600)
@RestController
@RequestMapping("/dynamic")
public class DynamicController {

    @Resource
    private DynamicService dynamicService;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public String get(String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

    /*
    返回一个动态的data
     */
    @RequestMapping("/getDynamic")
    @ResponseBody
    public List<Dynamic> getMainDyamic(int id, String token) {
        System.out.println(id);
        switch (id) {
            case 1: {
                if(token != null){
                   return dynamicService.getUserDynamic(dynamicService.getMainDyamic(),get(token));
                }
                return dynamicService.getMainDyamic();
            }
            case 2: {
                break;
            }
            case 3: {
                return dynamicService.getDynamicByFollow(get(token));
            }
        }
        return Collections.emptyList();
    }


}

